 <div class="item">
     <div class="item-l flex align-c">支付方式</div>
     <div class="item-m tr"></div>
     <div class="item-r"></div>
 </div>

<!-- 支付API列表，套板请务必将整块代码一起复制，包含隐藏域 -->
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
{eyou:sppayapilist id='vo'}
    {eyou:notempty name="$vo.pay_id"}
        {neq name="$vo.pay_mark" value="Hupijiaopay"}
             <div class="item pay-type-item" data-pay_id="{$vo.pay_id}" data-pay_mark="{$vo.pay_mark}">
                 <div class="item-l flex align-c"><span class="pay-icon pay-{$vo.pay_mark}"></span>{$vo.pay_name|rtrim=###,'支付'}</div>
                 <div class="item-m tr"></div>
                 <div class="item-r">
                     <span class="pay-select-btn"></span>
                 </div>
             </div>
        {/neq}
    {/eyou:notempty}
    {$vo.hidden}
{/eyou:sppayapilist}
<input type="hidden" id="PayID">
<input type="hidden" id="PayMark">
<!-- END -->

{eyou:if condition="1 != $data.transaction_type && 1 == $data.pay_balance_open"}
     <div class="item pay-type-item" id="PayBalancePayment" data-pay_mark="balance">
         <div class="item-l flex align-c"><span class="pay-icon pay-yuer"></span>余额</div>
         <div class="item-m flex align-c"><span class="ml10">账户余额:￥{$users.users_money}</span></div>
         <div class="item-r">
             <span class="pay-select-btn"></span>
         </div>
     </div>
    <script type="text/javascript">
        // 余额支付，购买商品+视频支付使用
        function PayBalancePayment() {
            layer.confirm('确认使用余额支付？', {
                title: false,
                btn: ['立即支付']
            }, function() {
                layer.closeAll();
                var unified_id = '{$data.unified_id}';
                var unified_number = '{$data.unified_number}';
                var transaction_type = '{$data.transaction_type}';
                if (!unified_number || !unified_id) layer.msg('订单号异常，请刷新重试', {time: 1500});

                // 禁止再次点击余额支付
                $('#PayBalancePayment').prop("disabled", true).find('.pay-select-btn').addClass('on');

                // 发送请求
                layer_loading('订单处理中');
                $.ajax({
                    url: '{$RootDir}/index.php?m=user&c=PayApi&a=balance_payment&_ajax=1',
                    data: {unified_id: unified_id, unified_number: unified_number, transaction_type: transaction_type},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        layer.closeAll();
                        if (1 == res.code) {
                            if (!res.data.mobile && !res.data.email) {
                                layer.msg(res.msg, {time: 1500}, function() {
                                    window.location.href = res.url;
                                });
                            } else {
                                if (res.data.mobile) SendMobile(res.data.mobile);
                                if (res.data.email) SendEmail(res.data.email);
                                layer.msg(res.msg, {time: 1500}, function() {
                                    window.location.href = res.url;
                                });
                            }
                        } else {
                            PayIsRecharge(res.msg, res.url);
                        }
                    }
                });
            });
        }

        // 是否要去充值
        function PayIsRecharge(msg ,url) {
            layer.confirm(msg, {
                title: false,
                btn: ['去充值','其他方式支付'],
                cancel: function(index, layero){ 
                    $('#PayBalancePayment').prop("disabled", false).find('.pay-select-btn').removeClass('on');
                }
            }, function() {
                // 去充值
                window.open(url); 
                
                layer.confirm('是否充值成功，立即支付？', {
                    title: false,
                    btn: ['立即支付','其他方式支付'],
                    cancel: function(index, layero){ 
                        $('#PayBalancePayment').prop("disabled", false).find('.pay-select-btn').removeClass('on');
                    }
                }, function() {
                    // 立即支付
                    PayBalancePayment();

                }, function(index) {
                    // 选择其他方式支付时，恢复禁用的余额支付按钮
                    $('#PayBalancePayment').prop("disabled", false).find('.pay-select-btn').removeClass('on');
                    layer.closeAll(index);
                });
            }, function(index) {
                // 选择其他方式支付时，恢复禁用的余额支付按钮
                $('#PayBalancePayment').prop("disabled", false).find('.pay-select-btn').removeClass('on');
                layer.closeAll(index);
            });
        }
    </script>
{/eyou:if}

<input type="hidden" id="pay_mark_1625652331">
<input type="hidden" id="pay_id_1625652331">
<script type="text/javascript">
    $(function(){
        $('.pay-type-item').click(function(){
            $(this).siblings().find('span.pay-select-btn').removeClass('on');
            $(this).find('span.pay-select-btn').addClass('on');
            var pay_mark = $(this).attr('data-pay_mark');
            $('#pay_mark_1625652331').val(pay_mark);
            var pay_id = $(this).attr('data-pay_id');
            $('#pay_id_1625652331').val(pay_id);
        });
        // 默认支付方式
        $($('.pay-type-item')[0]).trigger("click");
    });

    function gopay(obj)
    {
        var pay_mark = $('#pay_mark_1625652331').val();
        if ('balance' == pay_mark) {
            PayBalancePayment();
        } else {
            var pay_id = $('#pay_id_1625652331').val();
            SelectPayMethod(pay_id, pay_mark);
        }
    }
</script>